// 判断当前时间是上午1  下午2  晚上3
export function getCurrentTimeType() {
    const now = new Date()
    const hour = now.getHours()
    if (hour >= 6 && hour < 12) {
        return '1'
    } else if (hour >= 12 && hour < 18) {
        return '2'
    } else if (hour >= 0 && hour < 6) {
        return '3'
    } else if(hour >= 18 && hour < 23.99){
        return '3'
    }
}
// 可以重置任何页面的表单
export function resetForm(refName) {
    if (this.$refs[refName]) {
        this.$refs[refName].resetFields()
    }
}

// 可以重置任何页面的表单
export function reset1Form(refName) {
    if (this.$refs[refName]) {
      this.$refs[refName].resetFields()
    }
  }

/**
 * 公共的根据出生年月计算年龄的方法
 *  @param birthday 格式必须为2020-08-08
 */
export function getAge(birthday) {
    var birArr = birthday.split('-')
    var birYear = parseInt(birArr[0])
    var birMonth = parseInt(birArr[1])
    var birDay = parseInt(birArr[2])

    d = new Date()
    var nowYear = d.getFullYear()
    var nowMonth = d.getMonth() + 1 // 记得加1
    var nowDay = d.getDate()
    var returnAge

    if (birArr == null) {
        return false
    }
    var d = new Date(birYear, birMonth - 1, birDay)
    if (d.getFullYear() === birYear && (d.getMonth() + 1) === birMonth && d.getDate() === birDay) {
        if (nowYear === birYear) {
            returnAge = 0 //
        } else {
            var ageDiff = nowYear - birYear //
            if (ageDiff > 0) {
                if (nowMonth === birMonth) {
                    var dayDiff = nowDay - birDay //
                    if (dayDiff < 0) {
                        returnAge = ageDiff - 1
                    } else {
                        returnAge = ageDiff
                    }
                } else {
                    var monthDiff = nowMonth - birMonth //
                    if (monthDiff < 0) {
                        returnAge = ageDiff - 1
                    } else {
                        returnAge = ageDiff
                    }
                }
            } else {
                return '出生日期晚于今天，数据有误' // 返回-1 表示出生日期输入错误 晚于今天
            }
        }
        return returnAge
    } else {
        return ('输入的日期格式错误！')
    }
}
